require('./index.css')
var applyId = $CONFIG.page.applyId || '';
var oilCode = $CONFIG.page.oilCode || '';
import Vue from 'vue'
import 'assets/js/wii_entry';
import {Utils} from 'wmu2';
//import '../../../hy/comment/js/index.js'
import hello from '../components/public/hello'
var app = new Vue({
    el: '#app',
    data() {
        return {
            isSubmit:false,
            codeNum:'',
            applyId:applyId,
            oilCode:oilCode
        }
    },
    watch:{

    },
    mounted : function(){
        $('body').show();
        $('.J_Recharge  .submit').addClass('noClick');
//            $(".J_Card_no").on('input',function(){
//                if($(this).val()){
//                    $('.J_Recharge  .submit').removeClass('noClick');
//                }else{
//                    $('.J_Recharge  .submit').addClass('noClick');
//                }
//            })
// 表单提交
        $('.J_Recharge  .submit').click(function () {
            var self = this;
            var apply_id = $("input[name='apply_id']").val();
            var card_type = $('.J_Recharge').find('.btn-wrap .btn-on').attr('card_type');
            var card_no = $("input[name='card_no']").val();

            var isSubmit = true;
            // if(!card_no || hy.sb_strlen(realName)>12){
            if(!card_no){
                hy.popMsgh5('请填写加油卡号');
                isSubmit = false;
                return false;
            }
            if($(self).hasClass('noClick')){
                return false;
            }else{
                $(self).addClass('noClick');
            }
            hy.ajax({
                type: "post",
                url: "/act170901/h5api/recharge_oil_card",
                data: {apply_id: apply_id, card_type: card_type, card_no: card_no},
                dataType: "json",
                success: function (res) {
                    //TODO 这里少一个充值成功的状态；
                    var data  = res.data
                    if (res && res.data) {
                        window.location.href = res.data.jump_link;
                    }
                    if(data.oil_user_card_status == 1){
                        // 充值中
                        $('.J_Recharge').addClass('Z-hide');
                        $('.J_Czz').removeClass('hide')

//                            $('.recharge-ing').removeClass('.recharge-ing')
//                            $('.J_Recharge').addClass('Z-hide');
//                            $('.J_Recharge').removeClass('recharge-fail')
//                            $('.J_Recharge .fail-text').addClass('Z-hide');

                    }else if(data.oil_user_card_status == 3){
                        //充值失败
                        $('.recharge-ing').addClass('.recharge-ing')
                        $('.J_Recharge').removeClass('Z-hide');
                        $('.J_Recharge').addClass('recharge-fail')
                        $('.J_Recharge .fail-text').removeClass('Z-hide');
                    }
                },
                complete:function(){
                    $(self).removeClass('noClick');
                }
            },'J_submit',1);
            return false;
        });
        $('.J_Recharge').on('click','.btn',function(){
            $(this).parent().find('.btn').removeClass('btn-on');
            $(this).addClass('btn-on');
        })
    },
    components:{
        hello:hello
    },
    //相关操作事件
    methods: {
        //是否能提交
        chageIsSubmit(codeNum){
            if(codeNum){
                this.isSubmit = true;
            }else{
                this.isSubmit = false;
            }
        }
    }
})